import type {  MessageBodyInfo } from '@/wap';

let messageSubject;
export function useMessageSubject() {
  return messageSubject;
}

export function sendMessage(body: MessageBodyInfo) {
  messageSubject.next(body);
}
export function setMessageSubject(subject: any) {
  if (subject && !messageSubject) {
    messageSubject = subject;
    //  receiveMessage();
  }
}
// function receiveMessage() {
//   messageSubject.subscribe({
//     next: (body: MessageBodyInfo) => {
//       console.log('receive portal message', body);
//       if (body.operation == 'closePortalTab') { // 门户关闭当前标签页时，移除缓存中对应的组件
//         removeComponentWrapper(decodeURI((body.message as TabMessage).targetUrl));
//       } else if (body.operation == 'batchClosePortalTab') { // 门户关闭其它标签页时，移除缓存中对应的组件
//         const message = body.message as BatchTabMessage;
//         message.targetUrlList.forEach((item) => {
//           removeComponentWrapper(decodeURI(item));
//         });
//       }
//     },
//   });
// }
